/**
 * Created by Administrator on 2017/5/26.
 */

// import * as utils from './utils'
// 进入系统的url
function getEntryUrl() {
  return window.sessionStorage.getItem('entryurl')
}

function setEntryUrl(value) {
  window.sessionStorage.setItem('entryurl', value)
}

function getMemberInfo() {
  return JSON.parse(window.localStorage.getItem('member'))
}

/**
 * 存储当前登录用户信息
 * @param {Object} member
 */
function setMemberInfo(member) {
  window.localStorage.setItem('member', JSON.stringify(member))
}

function delMemberInfo() {
  window.localStorage.removeItem('member')
}

function getKey() {
  // return utils.getCookie('key')
  return window.localStorage.getItem('key')
}

function setKey(value) {
  // utils.setCookie('key', value, 360)
  window.localStorage.setItem('key', value)
}

function delKey() {
  // utils.delCookie('key')
  window.localStorage.removeItem('key')
}

function getPwd() {
  return window.localStorage.getItem('pwd')
}

function setPwd(value) {
  window.localStorage.setItem('pwd', value)
}

function delPwd() {
  window.localStorage.removeItem('pwd')
}

function getAuthed() {
  let value = window.localStorage.getItem('authored')
  if (value == 'true') {
    return true
  }
  return false
}

function setAuthed(boolValue) {
  if (boolValue) {
    window.localStorage.setItem('authored', 'true')
  } else {
    window.localStorage.setItem('authored', 'false')
  }
}

// 获取是否欢迎过的标识
function getWelcomed() {
  let value = window.sessionStorage.getItem('welcomed')
  if (value == 'true') {
    return true
  }
  return false
}

function setWelcomed(boolValue) {
  if (boolValue) {
    window.sessionStorage.setItem('welcomed', 'true')
  } else {
    window.sessionStorage.setItem('welcomed', 'false')
  }
}

function getCurrentGoodsCommonId() {
  return window.localStorage.getItem('currentgoodscommonid')
}

function setCurrentGoodsCommonId(value) {
  window.localStorage.setItem('currentgoodscommonid', value)
}

function delCurrentGoodsCommonId() {
  window.localStorage.removeItem('currentgoodscommonid')
}
function setBrandsData(value) {
  window.localStorage.setItem('brandsData', JSON.stringify(value))
}
function getBrandsData() {
  var brandsStr = window.localStorage.getItem('brandsData')
  if (brandsStr) {
    return JSON.parse(brandsStr)
  } else {
    return ''
  }
}
function setLocation(val) {
  if (val) {
    window.localStorage.setItem('location', JSON.stringify(val))
  }
}
function getLocationData() {
  var locationData = window.localStorage.getItem('location')
  if (locationData) {
    return JSON.parse(locationData)
  } else {
    return ''
  }
}
function setSearchKey(val, del) {
  if (del) {
    window.localStorage.setItem('searchKeywords', '')
    return
  }
  var tempKeys = window.localStorage.getItem('searchKeywords')
  if (tempKeys) {
    tempKeys = JSON.parse(tempKeys)
  } else {
    tempKeys = []
  }
  if (tempKeys.every(item => {
    return item !== val
  })) {
    tempKeys.push(val)
    window.localStorage.setItem('searchKeywords', JSON.stringify(tempKeys))
  }
}
function getSearchKey() {
  var tempKeys = window.localStorage.getItem('searchKeywords')
  if (tempKeys) {
    return JSON.parse(tempKeys)
  } else {
    return []
  }
}
export {
  getEntryUrl,
  setEntryUrl,
  getMemberInfo,
  setMemberInfo,
  delMemberInfo,
  getKey,
  setKey,
  delKey,
  getPwd,
  setPwd,
  delPwd,
  getWelcomed,
  setWelcomed,
  getAuthed,
  setAuthed,
  getCurrentGoodsCommonId,
  setCurrentGoodsCommonId,
  delCurrentGoodsCommonId,
  setBrandsData,
  getBrandsData,
  setLocation,
  getLocationData,
  setSearchKey,
  getSearchKey
}
